package cn.tianyigps.tianyigpsphpdatahandler.Customer;

import cn.tianyigps.tianyigpskafka.task.customer.NewCustomer;
import cn.tianyigps.tianyigpsphpdatahandler.Rest;
import cn.tianyigps.tianyigpspublic.param.bo.Task;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * @Author: WEI.YUAN
 * @Descirption:
 * @Date: 2019/4/27_16:04
 */
@Component
@Slf4j
public class Customer extends NewCustomer {
    @Autowired
    Rest rest;

    @Override
    public boolean checkTask(Task task) {
        Map<String, String> map = task.getParams();
        //参数不能为空
        if (CollectionUtils.isEmpty(map)) {
            return false;
        }
        //回调地址不能为空
        if (!map.containsKey("url") || StringUtils.isEmpty(map.get("url"))) {
            return false;
        }
        return true;
    }

    @Override
    public void consume(Task task) {
        rest.sendData(task.getParams());
    }
}
